package com.nhc.database.dbmodel;

import com.astrob.model.LonLat;
import com.astrob.naviframe.Start;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import java.util.ArrayList;

/**
 * http://blog.csdn.net/njweiyukun/article/details/51893092
 * Created by wsf on 2017/5/16.
 */
@Entity
public class Measure {

    @Id(autoincrement = true)
    private Long id;
    private String name = "";
    private double area = 0;//面积 平方米
    private double perimeter = 0;//周长-- 如果用户测量图形不是闭合的，那么周长等于用户走的轨迹长度加上起点和终点之间的距离）
    private double fee = 0; //费用
    private double per_price = 0; //单价
    private double length = 0; //长度   行走的轨迹点之间距离之和
    private long datetime = 0; //时间

    //实时面积测量
    private double areade = 0;//->等宽面积
    private double width = 0; //->等宽面积的宽度
    private double slopeangle = 0;//斜坡角度
    private int areatype = 0;//0-一般面积测量 1-等宽面积 2-斜坡面积

    private int type = 0;//type 0-length 1-area  2--农机测量列表machine 3-rule 4-slop 坡地

    private String note = "";//备用 json

    @Transient
    public ArrayList<MeasurePoint> measurePtList = null;//

    @Transient
    public int num = 0;//

    @Generated(hash = 918991248)
    public Measure(Long id, String name, double area, double perimeter, double fee,
            double per_price, double length, long datetime, double areade, double width,
            double slopeangle, int areatype, int type, String note) {
        this.id = id;
        this.name = name;
        this.area = area;
        this.perimeter = perimeter;
        this.fee = fee;
        this.per_price = per_price;
        this.length = length;
        this.datetime = datetime;
        this.areade = areade;
        this.width = width;
        this.slopeangle = slopeangle;
        this.areatype = areatype;
        this.type = type;
        this.note = note;
    }

    @Generated(hash = 1840334633)
    public Measure() {
    }

    public Measure(String name) {
        this.id = null;
        this.name = name;
        this.datetime = System.currentTimeMillis();
        measurePtList = new ArrayList<MeasurePoint>();
        if (name != null && name.compareToIgnoreCase("realtimeArea") == 0) {
            this.type = 1;
        }
    }

    public int getNum() {
        if (measurePtList == null) {
            return num;
        }
        return measurePtList.size();
    }

    public void add(LonLat ll, double alt) {
        if (ll == null || ll.IsInvalid()) {
            return;
        }
        if (measurePtList == null) {
            measurePtList = new ArrayList<MeasurePoint>();
        }

        MeasurePoint mp = new MeasurePoint(ll,  alt);

        int size = measurePtList.size();
        if (size > 0) {
            MeasurePoint mp0 = measurePtList.get(size - 1);
            double distance = Start.getInstance().MapKit().getDistance(mp0.getLL(), ll);
            if (distance < 5) {
                return;
            }
        }

        measurePtList.add(mp);
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getArea() {
        return this.area;
    }

    public void setArea(double area) {
        this.area = area;
    }

    public double getPerimeter() {
        return this.perimeter;
    }

    public void setPerimeter(double perimeter) {
        this.perimeter = perimeter;
    }

    public double getFee() {
        return this.fee;
    }

    public void setFee(double fee) {
        this.fee = fee;
    }

    public double getPer_price() {
        return this.per_price;
    }

    public void setPer_price(double per_price) {
        this.per_price = per_price;
    }

    public double getWidth() {
        return this.width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public long getDatetime() {
        return this.datetime;
    }

    public void setDatetime(long datetime) {
        this.datetime = datetime;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public double getLength() {
        return this.length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getSlopeangle() {
        return this.slopeangle;
    }

    public void setSlopeangle(double slopeangle) {
        this.slopeangle = slopeangle;
    }

    public int getAreatype() {
        return this.areatype;
    }

    public void setAreatype(int areatype) {
        this.areatype = areatype;
    }

    public double getAreade() {
        return this.areade;
    }

    public void setAreade(double areade) {
        this.areade = areade;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }


}
